package wibrst.sound {
	import com.reintroducing.sound.SoundManager;
	/**
	 * ...
	 * @author wibrst@qq.com
	 */
	public class SoundsHolder {
		
		/// singleton instance
		static private var _si:SoundsHolder;
		/// singleton instance
		static public function get si():SoundsHolder {
			if ( !_si ) {
				_si = new SoundsHolder;
			}
			return _si;
		}
		
		static public const MUSIC:Number = 0;
		static public const VOICE:Number= 1;
		static public const SOUND:Number = 2;
		
		private function SoundsHolder():void {
			_vcSoundSlot = new Vector.<SoundSlot>;
			_vcSoundSlot.push ( new SoundSlot );
			_vcSoundSlot.push ( new SoundSlot );
			_vcSoundSlot.push ( new SoundSlot );
		}
		
		public function stopSlotAll( nSlot:Number ):void {
			_vcSoundSlot[nSlot].stopAll();
		}
		
		public function stopSlotNow( nSlot:Number ):void {
				SoundManager.inst.stopSound( getSndIdPlaying(nSlot) );
		}
		
		public function playSnd( id:String, nSlot:Number, nStartTime:Number = 0, bStopPrev:Boolean = true ):void {
			trace( this, "playSnd ~~~", id, nSlot, nStartTime );
			if ( bStopPrev && getSndIdPlaying(nSlot) ) {
				stopSlotNow( nSlot );
			}
			SoundManager.inst.playSound( id, 1, nStartTime );
			
			_vcSoundSlot[nSlot].idPlaying = id;
			_vcSoundSlot[nSlot].vcIds.push( id );
		}
		
		private function getSndIdPlaying( nSlot:Number ):String {
			return _vcSoundSlot[nSlot].idPlaying;
		}
		
		public function read( vcSoundUnit:Vector.<SoundUnit> ) {
			for each( var soundUnit:SoundUnit in vcSoundUnit ) {
				SoundManager.inst.addExternalSound( soundUnit.url, soundUnit.id );
			}
		}
		
		private var _vcSoundSlot:Vector.<SoundSlot>;
		
	}

}